package com.city.controller.business;

import com.city.config.BaiduMap;
import com.city.config.Status;
import com.city.domain.report.CtReport;
import com.city.domain.report.CtTask;
import com.city.format.CtReportFormat;
import com.city.format.CtReportFormatSql;
import com.city.helper.AuthHelper;
import com.city.helper.FormatHelper;
import com.city.helper.TimeStampHelper;
import com.city.repository.report.CtReportFormatSqlRepository;
import com.city.service.pub.PubUserService;
import com.city.service.report.CtTaskService;
import com.city.service.report.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;


/**
 * @deprecation 业务处置手机端
 * @email leichuqiao@126.com
 * @author 雷楚桥
 * @date 2018-09-17 15:43
 */
@Controller
@RequestMapping("/business-mobile")
public class MobileController {

    @Autowired
    private AuthHelper authHelper;
    @Autowired
    private CtReportFormatSqlRepository sqlRepository;

    /**
     * @deprecation 详情浏览
     * @author 雷楚桥
     * @date 2018-07-06 21:47
     */
    @RequestMapping("/see")
    public String detail(Map<String,Object> map){
        System.out.println(authHelper.thisBranchId());
        List<CtReportFormatSql> ctReportFormatSqls = sqlRepository.findReport(1,7,authHelper.thisBranchId());
        updateSqs(map, ctReportFormatSqls);
        map.put("reportList", ctReportFormatSqls);
        map.put("titleName","业务处置详情浏览");
        return "/business/mobile/see";
    }

    /**
     * @deprecation 指挥派遣
     * @author 雷楚桥
     * @date 2018/7/29 18:32
     */
    @RequestMapping("/dispatch")
    public String dispatch(Map<String,Object> map){
        List<CtReportFormatSql> ctReportFormatSqls = sqlRepository.findReport(1,4,authHelper.thisBranchId());
        updateSqs(map, ctReportFormatSqls);
        map.put("titleName","指挥派遣");
        return "/business/mobile/dispatch";
    }
    static void updateSqs(Map<String, Object> map, List<CtReportFormatSql> sqs) {
        if(sqs.size() !=0){
            sqs.stream().forEach(ctReportFormatSql -> ctReportFormatSql.setScheduleName(Status.REPORT_SCHEDULE.get(ctReportFormatSql.getSchedule())));
            sqs.stream().forEach(ctReportFormatSql -> ctReportFormatSql.setCreateTimeName(new TimeStampHelper().stampToDate(ctReportFormatSql.getCreateTimeName())));
            map.put("reportList",sqs);
        }else {
            map.put("reportList",null);
        }
    }
}
